<template>
    <elm-page-bb class="elm-tree-edit">
        <elm-page-tb :splite="false" :splite-show="false">
            <template #top>
                <right>
                    <el-button-group>
                        <elm-open-button url="pj_task_edit" icon="el-icon-edit" title="新增" width="700" height="450" :data="{pid: '0', pj_id: postData.pj_id }">新增</elm-open-button>
                    </el-button-group>
                </right>
            </template>
            <elm-table-tree ref="table" url="/business/pmis/pj/task/GetTree" :post-data="postData" :default-expand-all="true" :page-size="9999" height="100%">
                <el-table-column type="index" label="序号" width="60px" align="center"></el-table-column>
                <el-table-column prop="name" label="工作名称" header-align="center"></el-table-column>
                <el-table-column prop="jh_start_time" :formatter="formatDateTime" label="计划开始时间" header-align="center"></el-table-column>
                <el-table-column prop="jh_end_time" :formatter="formatDateTime" label="计划结束时间" header-align="center"></el-table-column>
                <el-table-column prop="priority" label="优先级" header-align="center"></el-table-column>
                <el-table-column prop="status" label="状态" header-align="center"></el-table-column>
                <el-table-column prop="assignee_id" label="负责人" header-align="center">
                  <template v-slot="scope">
                    {{ eiList.find(item => item.key === scope.row.assignee_id)?.value || '未分配' }}
                  </template>
                </el-table-column>
                <el-table-column prop="sort" label="顺序" width="50px" align="center"></el-table-column>
                <el-table-column fixed="right" label="操作" width="160px" align="center">
                    <template v-slot="scope">
                        <elm-open-button url="pj_task_edit" :title="'编辑[' + scope.row.name + ']'" width="700" height="450" :data="{ model: scope.row }" type="text">编辑</elm-open-button>
                        <elm-open-button url="pj_task_edit" :title="'新增[' + scope.row.name + ']的下级'"  width="700" height="450"
                                         :data="{  pid: scope.row.id, pj_id: postData.pj_id }" type="text">新增下级</elm-open-button>
                        <el-button type="text" size="mini" @click="deleteData(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </elm-table-tree>
        </elm-page-tb>
        <template #bottom>
            <el-button size="small" @click="close">取消</el-button>
        </template>
    </elm-page-bb>
</template>

<script>
export default {
    extends: elmVueBase,
    data() {
        return {
            postData: { pj_id: elm.dialog.request.pj_id, name: null },
            eiList:[]
        }
    },
    async created() {
      this.eiList = await this.get_ei();
    },
    methods: {
        async deleteData(data) {
            await this.delete('/business/pmis/pj/task/Delete', { id: data.id });
            this.treebinding();
        },
      async get_ei(){
        var res = await elm.post('/business/my/business/GetEi');
        //console.log(res);
        if(res.length>0)
          return res;
        else
          return [];
      },
    }
}
</script>

<style scoped>
</style>